package com.robosense.datacenter.result;

public class R<T> {

    /********************************************************************
     * 返回成功的Json
     * *******************************************************************/
    public static<T> ResponseVO<T> success() {
        return success(null);
    }

    public  static<T> ResponseVO<T> success(String message) {
        return success(message, null);
    }

    public static<T> ResponseVO<T> success(String message, T data) {
        return vo(ResultType.SUCCESS.getCode(), message, data);
    }

    /********************************************************************
     * 返回失败的Json
     * *******************************************************************/
    public static<T> ResponseVO<T> failed() {
        return failed(null);
    }

    public static<T> ResponseVO<T> failed(String message) {
        return failed(message, null);
    }

    public static<T> ResponseVO<T> failed(String message, T data) {
        return vo(ResultType.FAILED.getCode(), message, data);
    }

    /********************************************************************
     * 返回自定义的Json
     * *******************************************************************/
    public static<T> ResponseVO<T> vo(int code, String message) {
        return vo(code, message, null);
    }

    public static<T> ResponseVO<T> vo(ResultType resultType) {
        return vo(resultType, null);
    }

    public static<T> ResponseVO<T> vo(ResultType resultType, T data) {
        return vo(resultType.getCode(), resultType.getMessage(), data);
    }

    public static<T> ResponseVO<T> vo(int code, String message, T data) {
        return new ResponseVO<>(code, message, data);
    }

   public enum ResultType {
        SUCCESS(200, "成功"),
        FAILED(500, "失败"),
        ;
        int code;
        String message;

        ResultType(int code, String message) {
            this.code = code;
            this.message = message;
        }

        public int getCode() {
            return code;
        }

        public String getMessage() {
            return message;
        }

    }
}
